package com.example.desionMode.cart;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author houyangfan
 * @version 1.0
 * @date 2022/8/4 18:32
 */
@RestController
public class CartController {

    @Autowired
    private ApplicationContext applicationContext;
    @GetMapping("/right")
    public Cart tranPrice(Integer uid){
        // 定义三种类型
        Map<Integer,String> map = new HashMap<>();
        map.put(1, "Normal");
        map.put(2, "Vip");
        map.put(3, "Internal");

        Map<Integer,Integer> itemMap = new HashMap<>();
        itemMap.put(1, 10);
        itemMap.put(2, 5);
        itemMap.put(3, 7);

        CommonCart commonCart = (CommonCart)applicationContext.getBean(map.get(uid) + "UserCart");
        return commonCart.process(uid, itemMap);

    }
}
